package admin.controller;

import admin.service.PropagandaService;
import common.model.Propaganda;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

//普法宣传资料管理

@RestController
@RequestMapping("/admin/propaganda")
public class PropagandaController {

    @Autowired
    private PropagandaService propagandaService;

    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Void> deletePropaganda(@PathVariable Long id) {
        propagandaService.deletePropaganda(id);
        return ResponseEntity.noContent().build();
    }

    @GetMapping("/find")
    public ResponseEntity<List<Propaganda>> findPropaganda(@RequestParam(required = false) Date date,
                                                           @RequestParam(required = false) String lawyerName,
                                                           @RequestParam(required = false) Boolean approved) {
        return ResponseEntity.ok(propagandaService.findPropaganda(date, lawyerName, approved));
    }

    @PutMapping("/approve/{id}")
    public ResponseEntity<Void> approvePropaganda(@PathVariable Long id) {
        propagandaService.approvePropaganda(id);
        return ResponseEntity.noContent().build();
    }
}